import jwt
from flask import current_app


class JwtTool:
    def gen_jwt(self,user,time):
        payload={
            'user_id':user.id,
            'exp':time
        }
        token=jwt.encode(payload,current_app.config.get('SECRET_KEY'))
        return token
    def vaild_jwt(self,token):
        try:
            payload=jwt.decode(token,current_app.get('SECRET_KEY'),algorithms='HS256')
        except Exception as e:
            print(e)
            return {}
        return payload